// 市场销售 / 档案管理

import r from '@/utils/request'
import { type ListResponseType, type ResponseType } from '../types'


enum API {
    fileitemsList = '/fileitems/list', // 所有档案文件项目
    elderlyFilesList = "/elderlyFiles/list", // 获取老人档案列表
    elderlyFilesAdd = "/elderlyFiles/add", // 老人档案添加
    elderlyFilesDelete = "/elderlyFiles/delete", // 删除老人档案信息
    elderlyFilesDownloadFile = "/elderlyFiles/downloadFile", // 老人档案文件下载
}

export interface fileListResAPI {
    id:   number;
    name: string;
}

export function fileitemsListAPI():Promise<ListResponseType<fileListResAPI>> {
    return r.get(API.fileitemsList)
}

export interface elderlyFilesListResAPI {
    id:        number;
    elderlyId: number;
    name:      string;
    fileName:  string;
}

export function elderlyFilesListAPI(id:number):Promise<ListResponseType<elderlyFilesListResAPI>> {
    return r.get(API.elderlyFilesList+'/'+id)
}

export interface elderlyFilesAddParamsAndResAPI {
    id:number;
    elderlyId: number;
    name:      string;
    fileName:  string;
}

export function elderlyFilesAddAPI(Params:elderlyFilesAddParamsAndResAPI):Promise<ResponseType<elderlyFilesAddParamsAndResAPI>> {
    return r.post(API.elderlyFilesAdd,Params)
}

export interface elderlyFilesDownloadFileParams {
    fileName: string;
}
// 存疑
export function elderlyFilesDownloadFileAPI(Params:elderlyFilesDownloadFileParams):Promise<Blob> {
    return r.post(API.elderlyFilesDownloadFile,Params,{responseType:'blob'})
}

export interface elderlyFilesDeleteParams {
    elderlyId:number;
    fileId:number;
}

export function elderlyFilesDeleteAPI(Params:elderlyFilesDeleteParams):Promise<ResponseType<null>> {
    return r.delete(API.elderlyFilesDelete+'/'+Params.elderlyId+'/'+Params.fileId)
}